<?php
	session_start();
	if(isset($_SESSION["nick"]))
	{
	//echo "hola";
	session_destroy();
	}
?>

<html>
<head>
<meta charset="utf-8">
<title>Login Pollos</title>
	  <style type="text/css">
			body{color: red;
			background-image: url("login.jpg");
			background-repeat: no-repeat;
			background-position:50% 0%;
			opacity: 0.94;
			 }
			#centro {
			position:absolute;
			left:40%;
			top:30%;
			border-left-width: 500px;
			text-align:center;
			padding:0 20px 0 20px ;
			background-color:#E6E6E6 ;
			width:400px;
			
			}
			
			#volver{position:absolute;
			left:90%;
			top:90%;
			}
	</style>
</head>
<body>
<div id="centro">
<form method='post' action='login.php'>
        	<p>Usuario:</p>
            <input type="text" name="nick"/>
            <p>Contrase&ntildea: </p>
            <input type="password" name="password"/>
			<br>
			<br>
            <button name="Entrar">Entrar</button>
        </form>
</div>
<div>
<form>
            <button id="volver" name="volver"><a href="index.html">volver</a></button>
 </form>
<div>
<?php
if (isset($_POST["Entrar"])){
	//mysql_connect('localhost','root')or die ('Ha fallado la conexión: '.mysql_error());
	//mysql_select_db('proyecto')or die ('Error al seleccionar la Base de Datos: '.mysql_error());
	require ("conexion.php");
	$usuario = $_POST["nick"];   
	$password = $_POST["password"];
	//$funcion = "";
	$result = mysql_query("SELECT * FROM usuarios WHERE nick = '$usuario'", $link);
	if($row = mysql_fetch_array($result)){
	if ($row["password"]==md5($password)){
	session_start();
	$_SESSION["nick"]=$usuario;
	//$_SESSION["funcion"]=$funcion;
	if ($row["funcion"]=="admin"){
	header("location: pollos.php");
	}
	elseif($row["funcion"]=="client"){
    header("location: cpollos.php");
	}
	elseif ($row["funcion"]=="emple"){
	header("location: epollos.php");
	}
	else {header("location: iniciopol.html");}
	
	}
	else{
	print "Contraseña incorrecta";
	}
	}
	else{
	print "Usuario incorrecto";
	}
	mysql_free_result($result);
	mysql_close();
	
	}
	
?>
</body>
</html>
